import pyodbc
from config import config


def execute_query(queryStatement):
    connection_string = (
        f"DRIVER={config.config_db['driver']};"
        f"SERVER={config.config_db['server']};"
        f"DATABASE={config.config_db['database']};"
        f"UID={config.config_db['username']};"
        f"PWD={config.config_db['password']}"
    )

    with pyodbc.connect(connection_string) as conn:
        with conn.cursor() as cursor:
            cursor.execute(queryStatement)
            results = cursor.fetchall()

    return results


def execute_statement(dml_statement):
    connection_string = (
        f"DRIVER={config.config_db['driver']};"
        f"SERVER={config.config_db['server']};"
        f"DATABASE={config.config_db['database']};"
        f"UID={config.config_db['username']};"
        f"PWD={config.config_db['password']}"
    )

    with pyodbc.connect(connection_string) as conn:
        with conn.cursor() as cursor:
            cursor.execute(dml_statement)
            conn.commit()
            return cursor.rowcount
